package model

import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Selector
import org.uqbar.arena.windows.Dialog
import org.uqbar.commons.utils.Observable
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.TextBox
import org.uqbar.arena.bindings.ObservableProperty
import org.uqbar.arena.bindings.PropertyAdapter
import unq.model.Lugar
import org.uqbar.arena.actions.MessageSend

@Observable
//EditarColeccionWindow
class EditorWindows<T> extends SimpleWindow<T>  {
	@Property String propiedad
	@Property String agregar
	@Property String eliminar 
	@Property String selector
	@Property Class clase
	new(WindowOwner owner,T model, String s, String agregar, String eliminar, String selector, Class o) {
		super(owner, model)
		this._propiedad = s
		this._agregar= agregar
		this._eliminar=eliminar
		this._selector= selector
		this._clase = o
		
	}
	
	override protected createFormPanel(Panel mainPanel) {
		
		this.setTitle("Editar" +" " + this.propiedad)
		
		new Label(mainPanel).setText("Caracteristicas")
		
		new List(mainPanel)=> [ 
			val binding = bindItemsToProperty(propiedad)
				binding.setAdapter(new PropertyAdapter(this.clase, "nombre"))
				bindValueToProperty("elem")
				width = 200
			    heigth = 50
				
		]
		new Button(mainPanel) => [
			caption = "eliminar"
			onClick = [|
				(new MessageSend(this.modelObject, this.eliminar)).execute
				close
			]
		]
		
		new Selector(mainPanel)=>[
			bindItemsToProperty(selector)
		    .setAdapter(new PropertyAdapter(this.clase, "nombre"))
			bindValueToProperty("elemObservado")
			width = 200
			heigth = 50
		]
		
		
		new Button(mainPanel) => [
			caption = "agregar"
			onClick [|(new MessageSend(this.modelObject, agregar)).execute
				//bindValue(new ObservableProperty(this.modelObject,"lista"))
				]	
			]
	}
	
	override protected addActions(Panel actionsPanel) {
		new Button(actionsPanel) => [
			caption = "aceptar"
			onClick[ | 
			close
			]
		]
	}
	
	
}